# encoding: utf-8
class Project < ActiveRecord::Base
	has_many :monitoring_files
	
	has_and_belongs_to_many :users, join_table: :user_projects

  belongs_to :owner, :class_name => "User", :foreign_key => "created_by"
  
  validates :name, uniqueness: true

  scope :active, -> { where("deleted_at IS NULL") }
  scope :deleted, -> { where("deleted_at IS NOT NULL") }
   
  def self.search(search, field)
    if search and field
      where(field + ' LIKE ?', "%#{search}%")
    else
      all
    end
  end
end
